package com.doit.day06

import java.text.Bidi

object _09_泛型 {
  def main(args: Array[String]): Unit = {

    //泛型的上下限
    /*    new Flower[Fu1](new Fu1)
        new Flower[Zi1](new Zi1)
    //    new Flower[Ye1](new Ye1)
    //    new Flower[Fu]()

        new Flower1[Ye1](new Ye1)
        new Flower1[Fu1](new Fu1)
    //    new Flower1[Zi1](new Zi1)*/


    //视图限定  限定的是什么
    class Bird(val name: String) {
      def fly() = {
        println(name + "飞走了")
      }
    }
    class ToyBird

    class A extends Bird("sss")

    //灵魂拷问，bird的子类能不能往里面传

    //视图限定限定一个类型  后面用这个泛型的参数对象就可以调用限定这个类型里面所有的方法
    def bitBird[T <% Bird](b: T) = b.fly()

    bitBird[Bird](new Bird("小鸟"))

    //必须得让ToyBird拥有Bird里面的fly方法
    implicit def toyBird2Bird(toyBird: ToyBird)={
      new Bird("玩具鸟")
    }
    //什么东西可以往里面传  必须得是可以调用Bird这个类中的fly方法才可以往里面传
    bitBird[ToyBird](new ToyBird)

    implicit def int2Bird(toyBird: Int)={
      new Bird("玩具鸟")
    }
    bitBird[Int](10)

    bitBird(new A)


    /*

      implicit def toy2Bird(toyBird: ToyBird)= new Bird("玩具鸟")

      */


  }
}


//创建Flower独享的时候，穿进去的参数只能是Fu1或者Fu1的子类
class Flower[A <: Fu1](a: A)

class Flower1[A >: Fu1](a: A)


class Ye1

class Fu1 extends Ye1

class Zi1 extends Fu1

